package com.bookstore.service;


import com.bookstore.entity.User;
import com.bookstore.mapper.UserMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户账户查找用户
     * @param account
     * @return
     */
    public User findUserByAccount(String account){
        User user = userMapper.findUserByAccount(account);
        return user;
    }

    /**
     *更新用户
     * @param user  用户对象
     * @return 是否更新成功
     */
    @Transactional
    public boolean updateUser(User user){
        if (userMapper.updateByPrimaryKeySelective(user) == 0)
            return false;
        else
            return true;
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Transactional
    public boolean insertUser(User user){
        if (userMapper.insertSelective(user) == 0)
            return false;
        else
            return true;
    }



}
